package com.ymatou.iapi.productmanager.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.parameter.GetAlhProductsRebateRateBean;
import com.ymatou.iapi.productmanager.parameter.alhbean.ProductRebateRateDto;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.GetAlhProductsRebateRateCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.utils.EnvSetup;

import sun.util.logging.resources.logging;
/**
*通过商品id列表查询安利会费率Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetAlhProductsRebateRate{
	private static GetAlhProductsRebateRateBean getalhproductsrebaterateBean;
	private static GetAlhProductsRebateRateCall getalhproductsrebaterateCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("通过商品id列表查询安利会费率Test");
	}

	@Before
	public void caseUp() {
		getalhproductsrebaterateBean=new GetAlhProductsRebateRateBean();
		getalhproductsrebaterateCall=new GetAlhProductsRebateRateCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getalhproductsrebaterateCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetAlhProductsRebateRate_001() {
		Logger.start(true,"正确数据，查询成功");
		try {
			
			String getalhProductId = ProductManagerCallServiceV2.getalhProductId();
			getalhproductsrebaterateBean.setUserId(sellerId);
			
			getalhproductsrebaterateCall.setData(getalhproductsrebaterateBean);
			getalhproductsrebaterateCall.callService();			
			
			Logger.verifyEquals("200", getalhproductsrebaterateCall.getString("Code"), "验证code");
			List<ProductRebateRateDto> productRebateRateDtos = getalhproductsrebaterateCall.getProductRebateRateDtos();
			productRebateRateDtos.forEach(b->{
				String productId = b.getProductId();
				if(getalhProductId.equals(productId)){
					Logger.verifyEquals("0.0300", b.getRebateRate().toString(), "判断基准值是否正确");
				}
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetAlhProductsRebateRate_002() {
		Logger.start(true,"买手id为空，查询失败");
		try {
			getalhproductsrebaterateBean.setUserId(null);
			
			getalhproductsrebaterateCall.setData(getalhproductsrebaterateBean);
			getalhproductsrebaterateCall.callService();			
			Logger.verifyEquals("400", getalhproductsrebaterateCall.getString("Code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetAlhProductsRebateRate_003() {
		Logger.start(true,"时间判断");
		try {
			
			String getalhProductId = ProductManagerCallServiceV2.getalhProductId();
			getalhproductsrebaterateBean.setUserId(sellerId);
			
			getalhproductsrebaterateCall.setData(getalhproductsrebaterateBean);
			getalhproductsrebaterateCall.callService();			
			
			Logger.verifyEquals("200", getalhproductsrebaterateCall.getString("Code"), "验证code");
			List<ProductRebateRateDto> productRebateRateDtos = getalhproductsrebaterateCall.getProductRebateRateDtos();
			productRebateRateDtos.forEach(b->{
				String startTime = b.getStartTime();
				Logger.verifyNotEquals("", startTime, "有时间");
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}